#include <cppunit/config/SourcePrefix.h>
#include "TestModifies.h"
#include <string>

void TestModifies::setUp() {
}

void TestModifies::tearDown() {
}

CPPUNIT_TEST_SUITE_REGISTRATION( TestModifies );

void TestModifies::testAddGetStatementModifies(){
	Modifies mod = Modifies();
	mod.addStmtModifies(1, 0);
	mod.addStmtModifies(2, 0);
	mod.addStmtModifies(3, 0);
	mod.addStmtModifies(4, 1);
	mod.addStmtModifies(5, 2);
	mod.addStmtModifies(6, 3);
	mod.addStmtModifies(7, 4);
	mod.addStmtModifies(8, 3);
	mod.addStmtModifies(9, 2);
	int index = mod.addStmtModifies(10,1);

	vector<pair<int,int>> anyany = mod.getModifiesStatement(ANYVALUE, ANYVALUE);
	int size = anyany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("All results return", index+1, size);
	
	vector<pair<int,int>> anynum = mod.getModifiesStatement(ANYVALUE, 1);
	size = anynum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("2 results found", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (4,1)", 4, anynum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (10,1)", 10, anynum.at(1).first);

	vector<pair<int,int>> numany = mod.getModifiesStatement(7, ANYVALUE);
	size = numany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Only 1 result found; One statement can modify only 1 variable", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (7,4)", 4, numany.at(0).second);

	vector<pair<int,int>> numnum = mod.getModifiesStatement(9, 2);
	size = numnum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("1 result found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (9,2)", 9, numnum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (9,2)", 2, numnum.at(0).second);

	vector<pair<int,int>> none = mod.getModifiesStatement(3, 3);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("no result found", 0, size);
}

void TestModifies::testAddGetProcedureModifies(){
	Modifies mod = Modifies();
	mod.addProcModifies(0, 0);
	mod.addProcModifies(0, 1);
	mod.addProcModifies(0, 2);
	mod.addProcModifies(0, 3);
	mod.addProcModifies(0, 4);
	mod.addProcModifies(1, 0);
	mod.addProcModifies(1, 2);
	mod.addProcModifies(1, 4);
	mod.addProcModifies(2, 5);
	int index = mod.addProcModifies(3, 6);

	vector<pair<int,int>> anyany = mod.getModifiesProcedure(ANYVALUE, ANYVALUE);
	int size = anyany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("All results return", index+1, size);
	
	vector<pair<int,int>> anynum = mod.getModifiesProcedure(ANYVALUE, 0);
	size = anynum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("2 results found", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (0,0)", 0, anynum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (1,0)", 1, anynum.at(1).first);

	vector<pair<int,int>> numany = mod.getModifiesProcedure(2, ANYVALUE);
	size = numany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("1 result found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (2,5)", 5, numany.at(0).second);

	vector<pair<int,int>> numnum = mod.getModifiesProcedure(3, 6);
	size = numnum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("1 result found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (3,6)", 3, numnum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (3,6)", 6, numnum.at(0).second);

	vector<pair<int,int>> none = mod.getModifiesProcedure(4, 0);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("no result found", 0, size);
}